const Koa = require('koa')
const next = require('next')

console.log('process.env.NODE_ENV = ', process.env.NODE_ENV )

const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()

app.prepare().then(() => {
  const server = new Koa()
  server.use(async (ctx, next) => {
    await handle(ctx.req, ctx.res)
    ctx.respond = false
  })

  server.listen(3003, () => {
    console.log('server is running at http://localhost:3003')
  })
})